package org.edu.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Proxy;

@Entity
@Proxy(lazy = false)
@Table(name = "LESSON", catalog = "SCHOOL")
public class Lesson implements Serializable {

	private static final long serialVersionUID = 1L;

	private Long lesson_id;
	private String lesson_code;
	private Semester semesters;
	private Sciency sciencyL;
	private Set<TeacherLesson> teacherLessons = new HashSet<>();
	private String lesson_name;
	private String credit;
	private String hour;
	private Boolean status_teach;
	private Boolean status_stu;
	private Integer quota;
	private Boolean status_les;

	@Id
	@GeneratedValue
	@Column(name = "LESSON_ID")
	public Long getLesson_id() {
		return lesson_id;
	}

	public void setLesson_id(Long lesson_id) {
		this.lesson_id = lesson_id;
	}

	@Column(name = "LESSON_CODE", nullable = false)
	public String getLesson_code() {
		return lesson_code;
	}

	public void setLesson_code(String lesson_code) {
		this.lesson_code = lesson_code;
	}


	@ManyToOne
	@JoinColumn(name = "SEMESTER_ID")
	public Semester getSemesters() {
		return semesters;
	}

	public void setSemesters(Semester semesters) {
		this.semesters = semesters;
	}
	
	@ManyToOne
	@JoinColumn(name = "SCIENCY_ID")
	public Sciency getSciencyL() {
		return sciencyL;
	}

	public void setSciencyL(Sciency sciencyL) {
		this.sciencyL = sciencyL;
	}

	@OneToMany(targetEntity = TeacherLesson.class, mappedBy = "lesson", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	public Set<TeacherLesson> getTeacherLessons() {
		return teacherLessons;
	}

	public void setTeacherLessons(Set<TeacherLesson> teacherLessons) {
		this.teacherLessons = teacherLessons;
	}

	@Column(name = "LESSON_NAME")
	public String getLesson_name() {
		return lesson_name;
	}

	public void setLesson_name(String lesson_name) {
		this.lesson_name = lesson_name;
	}

	@Column(name = "CREDIT")
	public String getCredit() {
		return credit;
	}

	public void setCredit(String credit) {
		this.credit = credit;
	}

	@Column(name = "HOUR")
	public String getHour() {
		return hour;
	}

	public void setHour(String hour) {
		this.hour = hour;
	}

	@Column(name = "STATUS_TEACH")
	public Boolean getStatus_teach() {
		return status_teach;
	}

	public void setStatus_teach(Boolean status_teach) {
		this.status_teach = status_teach;
	}

	@Column(name = "STATUS_STU")
	public Boolean getStatus_stu() {
		return status_stu;
	}

	public void setStatus_stu(Boolean status_stu) {
		this.status_stu = status_stu;
	}

	@Column(name = "QUOTA")
	public Integer getQuota() {
		return quota;
	}

	public void setQuota(Integer quota) {
		this.quota = quota;
	}

	@Column(name = "STATUS_LES")
	public Boolean getStatus_les() {
		return status_les;
	}

	public void setStatus_les(Boolean status_les) {
		this.status_les = status_les;
	}

	public Lesson() {
		super();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((credit == null) ? 0 : credit.hashCode());
		result = prime * result + ((hour == null) ? 0 : hour.hashCode());
		result = prime * result
				+ ((lesson_code == null) ? 0 : lesson_code.hashCode());
		result = prime * result
				+ ((lesson_id == null) ? 0 : lesson_id.hashCode());
		result = prime * result
				+ ((lesson_name == null) ? 0 : lesson_name.hashCode());
		result = prime * result + ((quota == null) ? 0 : quota.hashCode());
		result = prime * result
				+ ((status_les == null) ? 0 : status_les.hashCode());
		result = prime * result
				+ ((status_stu == null) ? 0 : status_stu.hashCode());
		result = prime * result
				+ ((status_teach == null) ? 0 : status_teach.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Lesson other = (Lesson) obj;
		if (credit == null) {
			if (other.credit != null)
				return false;
		} else if (!credit.equals(other.credit))
			return false;
		if (hour == null) {
			if (other.hour != null)
				return false;
		} else if (!hour.equals(other.hour))
			return false;
		if (lesson_code == null) {
			if (other.lesson_code != null)
				return false;
		} else if (!lesson_code.equals(other.lesson_code))
			return false;
		if (lesson_id == null) {
			if (other.lesson_id != null)
				return false;
		} else if (!lesson_id.equals(other.lesson_id))
			return false;
		if (lesson_name == null) {
			if (other.lesson_name != null)
				return false;
		} else if (!lesson_name.equals(other.lesson_name))
			return false;
		if (quota == null) {
			if (other.quota != null)
				return false;
		} else if (!quota.equals(other.quota))
			return false;
		if (status_les == null) {
			if (other.status_les != null)
				return false;
		} else if (!status_les.equals(other.status_les))
			return false;
		if (status_stu == null) {
			if (other.status_stu != null)
				return false;
		} else if (!status_stu.equals(other.status_stu))
			return false;
		if (status_teach == null) {
			if (other.status_teach != null)
				return false;
		} else if (!status_teach.equals(other.status_teach))
			return false;
		return true;
	}
	
}
